package com.group9.handinhand.controller.form;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import com.group9.handinhand.service.so.ActivityEnums.ActivityType;
import com.group9.handinhand.service.so.OfferSO;
import com.group9.handinhand.service.so.TagSO;
import com.group9.handinhand.service.so.UserSO;
/**
 * 
 * @Class OfferUpdateForm
 * Updates the offer form
 *
 */
public class OfferUpdateForm {
	
	OfferSO offer;
	List<UserSO> moderators;
	String selectedTags;
	String endingDay;
	String endingHour;
	
	
	public OfferUpdateForm() {
		// TODO Auto-generated constructor stub
	}
	/**
	 * A getter method.
	 * @return offer
	 */
	public OfferSO getOffer() {
		return offer;
	}
	/**
	 * A setter method.
	 * @param offer
	 */
	public void setOffer(OfferSO offer) {
		this.offer = offer;
	}
	/**
	 * A getter method.
	 * @return the list of moderators.
	 */
	public List<UserSO> getModerators() {
		return moderators;
	}
	/**
	 * A setter method.
	 * @param moderators
	 */
	public void setModerators(List<UserSO> moderators) {
		this.moderators = moderators;
	}
	/**
	 * A getter method.
	 * @return selectedTags
	 */
	public String getSelectedTags() {
		return selectedTags;
	}
	/**
	 * A setter method.
	 * @param selectedTags
	 */
	public void setSelectedTags(String selectedTags) {
		this.selectedTags = selectedTags;
	}
	/**
	 * A getter method.
	 * @return endingDay of the offer
	 */
	public String getEndingDay() {
		return endingDay;
	}
	/**
	 * A setter method.
	 * @param endingDay
	 */
	public void setEndingDay(String endingDay) {
		this.endingDay = endingDay;
	}
	/**
	 * A getter method
	 * @return ending hour of the offer
	 */
	public String getEndingHour() {
		return endingHour;
	}
	/**
	 * A setter method.
	 * @param endingHour
	 */
	public void setEndingHour(String endingHour) {
		this.endingHour = endingHour;
	}
	/**
	 * A getter method.
	 * @return the list of selected tags as a list.
	 */
	public List<String> getSelectedTagsAsList() {
		String[] tags = selectedTags.split(",");
		return Arrays.asList(tags);
	}
	/**
	 * A setter method.
	 * @param soList
	 */
	public void setSelectedTagsFromList(List<TagSO> soList) {
		selectedTags = "";
		if(soList.size()==0)
			return;
		selectedTags += soList.get(0).getTagName();
		soList.remove(0);
		for (TagSO tag : soList) {
			selectedTags += ", " + tag.getTagName();
		}
	}
	/**
	 * Sets ending dates which include ending days and hours also.
	 */
	public void setEndDate() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
		
		String endingDate = endingDay + " " + endingHour;
		
		try {
			offer.setExpirationDate(dateFormat.parse(endingDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
	}
}
